<template>
  <div class="publicpageview">
    <div class="publicformview">
      <el-form :inline="true" :model="listQuery" size="mini" ref="searchForm">
        <el-row :gutter="20">
          <el-col :span="4">
            <el-form-item label="区房屋管理单位：" prop="districtUnit">
              <el-select v-model="listQuery.districtUnit" placeholder="全部" style="width: 100%">
                <el-option label="全部" value=""></el-option>
                <el-option label="和平区管理中心" value="1"></el-option>
                <el-option label="河东区管理中心" value="2"></el-option>
                <el-option label="河西区管理中心" value="3"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="管理部(分中心)：" prop="managementDept">
              <el-select v-model="listQuery.managementDept" placeholder="全部" style="width: 100%">
                <el-option label="全部" value=""></el-option>
                <el-option label="第一管理部" value="1"></el-option>
                <el-option label="第二管理部" value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="管片：" prop="district">
              <el-select v-model="listQuery.district" placeholder="全部" style="width: 100%">
                <el-option label="全部" value=""></el-option>
                <el-option label="王三" value="1"></el-option>
                <el-option label="李四" value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="所号：" prop="houseNumber">
              <el-select v-model="listQuery.houseNumber" placeholder="全部" style="width: 100%">
                <el-option label="全部" value=""></el-option>
                <el-option label="9854" value="9854"></el-option>
                <el-option label="9855" value="9855"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="附属：" prop="accessory">
              <el-select v-model="listQuery.accessory" placeholder="全部" style="width: 100%">
                <el-option label="全部" value=""></el-option>
                <el-option label="主房" value="0"></el-option>
                <el-option label="附属" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="地址：" prop="address">
              <el-input v-model="listQuery.address" placeholder="请输入地址"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="4">
            <el-form-item label="管理形式：" prop="managementType">
              <el-select v-model="listQuery.managementType" placeholder="全部" style="width: 100%">
                <el-option label="全部" value=""></el-option>
                <el-option label="直管" value="1"></el-option>
                <el-option label="代管" value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="产别：" prop="propertyType">
              <el-select v-model="listQuery.propertyType" placeholder="全部" style="width: 100%">
                <el-option label="全部" value=""></el-option>
                <el-option label="住宅" value="1"></el-option>
                <el-option label="商业" value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="门号：" prop="doorNumber">
              <el-input v-model="listQuery.doorNumber" placeholder="请输入门号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="性质：" prop="nature">
              <el-select v-model="listQuery.nature" placeholder="全部" style="width: 100%">
                <el-option label="全部" value=""></el-option>
                <el-option label="居住" value="1"></el-option>
                <el-option label="商用" value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="经营：" prop="business">
              <el-select v-model="listQuery.business" placeholder="全部" style="width: 100%">
                <el-option label="全部" value=""></el-option>
                <el-option label="经营" value="1"></el-option>
                <el-option label="不经营" value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="承租人：" prop="tenant">
              <el-input v-model="listQuery.tenant" placeholder="请输入承租人"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="4">
            <el-form-item label="合同编号：" prop="contractNumber">
              <el-input v-model="listQuery.contractNumber" placeholder="请输入合同编号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="身份证号：" prop="idNumber">
              <el-input v-model="listQuery.idNumber" placeholder="请输入身份证号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="运约金：" prop="securityDeposit">
              <el-select v-model="listQuery.securityDeposit" placeholder="全部" style="width: 100%">
                <el-option label="全部" value=""></el-option>
                <el-option label="已交" value="1"></el-option>
                <el-option label="未交" value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="可盈：" prop="profitable">
              <el-select v-model="listQuery.profitable" placeholder="全部" style="width: 100%">
                <el-option label="全部" value=""></el-option>
                <el-option label="可盈" value="1"></el-option>
                <el-option label="不可盈" value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="日期：" prop="date">
              <el-date-picker v-model="listQuery.date" type="date" placeholder="年/月/日" style="width: 100%">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <div>
              <el-button size="mini" type="primary" @click="handleSearch">查询</el-button>
              <el-button size="mini" @click="resetForm('searchForm')">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </div>
        
    <div class="publitableview">
      <el-button type="primary" size="mini" @click="handleAddContract">合同录入</el-button>
      <el-table v-loading="listLoading" :data="list" border fit highlight-current-row size="mini">
        <el-table-column align="center" label="序号" type="index" width="60">
        </el-table-column>

        <el-table-column align="center" label="合同编号" prop="contractNumber" min-width="120">
        </el-table-column>

        <el-table-column align="center" label="合同文本序号" prop="contractTextNumber" min-width="120">
        </el-table-column>

        <el-table-column align="center" label="订约" prop="signContract" width="80">
        </el-table-column>

        <el-table-column align="center" label="退约" prop="terminateContract" width="80">
        </el-table-column>

        <el-table-column align="center" label="起租" prop="startRent" width="100">
        </el-table-column>

        <el-table-column align="center" label="停租" prop="stopRent" width="100">
        </el-table-column>

        <el-table-column align="center" label="承租人" prop="tenant" min-width="100">
        </el-table-column>

        <el-table-column align="center" label="操作" width="350" fixed="right">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="handleUploadScan(scope.row)">扫描件上传</el-button>
            <el-button type="text" size="mini" @click="handlePrint(scope.row)">打印</el-button>
            <el-button type="text" size="mini" @click="handleJointSign(scope.row)">续签</el-button>
            <el-button type="text" size="mini" @click="handleUpdate(scope.row)">修改</el-button>
            <el-button type="text" size="mini" @click="handleView(scope.row)">详情</el-button>
            <el-button type="text" size="mini" @click="handleDelete(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
			
      <div class="publicpaginationview">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
          :current-page="listQuery.page" background :page-sizes="[10, 20, 50, 100]" :page-size="listQuery.limit"
          layout="total, sizes, prev, pager, next, jumper" :total="total" small></el-pagination>
      </div>
    </div>

    <!-- 租赁合同录入弹窗 -->
    <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="1200px" @close="handleDialogClose">
      <el-form :model="formData" :rules="formRules" ref="contractForm" label-width="130px" size="small">
        <div class="contract-form">
          <!-- 合同信息 -->
          <h4 class="section-title">合同信息</h4>
          <el-row :gutter="20">
            <el-col :span="6">
              <el-form-item label="合同编号：" prop="contractNumber">
                <el-input v-model="formData.contractNumber" :disabled="isReadonly" placeholder="请输入合同编号"></el-input>
              </el-form-item>
            </el-col>
          <el-col :span="6">
            <el-form-item label="合同文本序号：" prop="contractTextNumber">
              <el-input v-model="formData.contractTextNumber" :disabled="isReadonly" placeholder="请输入合同文本序号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="订约：">
              <el-date-picker v-model="formData.signDate" :disabled="isReadonly" type="date" placeholder="年/月/日" style="width: 100%">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="退约：">
              <el-date-picker v-model="formData.terminateDate" :disabled="isReadonly" type="date" placeholder="年/月/日" style="width: 100%">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="起租：">
              <el-date-picker v-model="formData.startRentDate" :disabled="isReadonly" type="date" placeholder="年/月/日" style="width: 100%">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="停租：">
              <el-date-picker v-model="formData.stopRentDate" :disabled="isReadonly" type="date" placeholder="年/月/日" style="width: 100%">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 承租人信息 -->
        <h4 class="section-title">承租人信息</h4>
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="承租人：" prop="tenant">
              <el-input v-model="formData.tenant" :disabled="isReadonly" placeholder="请输入承租人"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="证件类型：">
              <el-select v-model="formData.idType" :disabled="isReadonly" placeholder="身份证号" style="width: 100%">
                <el-option label="身份证号" value="id_card"></el-option>
                <el-option label="护照" value="passport"></el-option>
                <el-option label="其他" value="other"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="证件号码：">
              <el-input v-model="formData.idNumber" :disabled="isReadonly" placeholder="请输入证件号码"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 房屋信息 -->
        <h4 class="section-title">房屋信息</h4>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="手机号码：">
              <el-input v-model="formData.phoneNumber" :disabled="isReadonly" placeholder="请输入手机号码"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="机编号码：">
              <el-input v-model="formData.machineNumber" :disabled="isReadonly" placeholder="请输入机编号码"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="管片：">
              <el-input v-model="formData.district" :disabled="isReadonly" placeholder="请输入管片"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="所号：">
              <el-select v-model="formData.houseNumber" :disabled="isReadonly" placeholder="1" style="width: 100%">
                <el-option label="1" value="1"></el-option>
                <el-option label="2" value="2"></el-option>
                <el-option label="3" value="3"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="门号：">
              <el-input v-model="formData.doorNumber" :disabled="isReadonly" placeholder="请输入门号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="产别：">
              <el-input v-model="formData.propertyType" :disabled="isReadonly" placeholder="请输入产别"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="层室间号：">
              <el-input v-model="formData.roomNumber" :disabled="isReadonly" placeholder="请输入层室间号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="地址：">
              <el-input v-model="formData.address" :disabled="isReadonly" placeholder="请输入地址"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="产别：">
              <el-select v-model="formData.propertyCategory" :disabled="isReadonly" placeholder="公产" style="width: 100%">
                <el-option label="公产" value="public"></el-option>
                <el-option label="私产" value="private"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="管理形式：">
              <el-select v-model="formData.managementType" :disabled="isReadonly" placeholder="1" style="width: 100%">
                <el-option label="1" value="1"></el-option>
                <el-option label="2" value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="性质：">
              <el-select v-model="formData.nature" :disabled="isReadonly" placeholder="1" style="width: 100%">
                <el-option label="1" value="1"></el-option>
                <el-option label="2" value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="成套：">
              <el-select v-model="formData.isComplete" :disabled="isReadonly" placeholder="李四" style="width: 100%">
                <el-option label="李四" value="li_si"></el-option>
                <el-option label="王五" value="wang_wu"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 租金详细 -->
        <h4 class="section-title">租金详细</h4>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="可盈：">
              <el-select v-model="formData.profitable" :disabled="isReadonly" placeholder="不可盈" style="width: 100%">
                <el-option label="不可盈" value="no"></el-option>
                <el-option label="可盈" value="yes"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="居室回数：">
              <el-input v-model="formData.roomCount" :disabled="isReadonly" placeholder="请输入居室回数"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="独用自然间数：">
              <el-input v-model="formData.exclusiveRooms" :disabled="isReadonly" placeholder="请输入独用自然间数"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="伙用自然间数：">
              <el-input v-model="formData.sharedRooms" :disabled="isReadonly" placeholder="请输入伙用自然间数"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="独用共相间数：">
              <el-input v-model="formData.exclusiveSharedRooms" :disabled="isReadonly" placeholder="请输入独用共相间数"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="伙用共相间数：">
              <el-input v-model="formData.sharedSharedRooms" :disabled="isReadonly" placeholder="请输入伙用共相间数"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="降低相间数：">
              <el-input v-model="formData.reducedRooms" :disabled="isReadonly" placeholder="请输入降低相间数"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="租金金额：">
              <el-input v-model="formData.rentAmount" :disabled="isReadonly" placeholder="请输入租金金额"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="盈亏：">
              <el-select v-model="formData.profitLoss" :disabled="isReadonly" placeholder="1" style="width: 100%">
                <el-option label="1" value="1"></el-option>
                <el-option label="2" value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="承租：">
              <el-input v-model="formData.rentStatus" :disabled="isReadonly" placeholder="请输入承租状态"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="月实收数：">
              <el-input v-model="formData.monthlyReceived" :disabled="isReadonly" placeholder="请输入月实收数"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="核减回数：">
              <el-select v-model="formData.verifiedReduction" :disabled="isReadonly" placeholder="低保" style="width: 100%">
                <el-option label="低保" value="low_income"></el-option>
                <el-option label="普通" value="normal"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 其他信息 -->
        <h4 class="section-title">其他信息</h4>
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="连约金库：">
              <el-input v-model="formData.jointContractDeposit" :disabled="isReadonly" placeholder="请输入连约金库"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="机约备件：">
              <el-input v-model="formData.machineContractParts" :disabled="isReadonly" placeholder="请输入机约备件"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="备注：">
              <el-input v-model="formData.remarks" :disabled="isReadonly" placeholder="请输入备注"></el-input>
            </el-form-item>
          </el-col>
          </el-row>
        </div>
      </el-form>
      
      <div slot="footer" class="dialog-footer">
        <el-button v-if="!isReadonly" type="primary" @click="handleSubmit" :loading="submitLoading">保存</el-button>
        <el-button @click="dialogVisible = false">{{ isReadonly ? '关闭' : '取消' }}</el-button>
      </div>
    </el-dialog>

    <!-- 扫描件上传组件 -->
    <FileUpload
      :visible.sync="uploadDialogVisible"
      title="扫描件上传"
      width="900px"
      file-type-text="扫描件"
      :file-list-title="'扫描件列表'"
      :show-template="false"
      :show-preview="true"
      confirm-text="确定"
      :max-size="10"
      accept=".pdf,.jpg,.jpeg,.png,.gif,.doc,.docx"
      tip-text="只能上传pdf/jpg/png/gif/doc/docx文件，且不超过10MB"
      @confirm="handleUploadConfirm"
      @preview="handleFilePreview"
      @close="handleUploadClose"
    />

    <!-- 租赁合同打印弹窗 -->
    <el-dialog title="租赁合同打印" :visible.sync="printDialogVisible" width="600px" @close="handlePrintDialogClose">
      <div class="print-container">
        <div class="print-preview">
          <div class="print-style-text">打印样式</div>
        </div>
      </div>
      
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleDoPrint">打印</el-button>
      </div>
    </el-dialog>

    <!-- 租赁合同续签弹窗 -->
    <el-dialog title="租赁合同续签" :visible.sync="renewDialogVisible" width="400px" @close="handleRenewDialogClose">
      <div class="renew-container">
        <el-form :model="renewFormData" label-width="130px" size="small">
          <el-form-item label="新的生效日期：" required>
            <el-date-picker 
              v-model="renewFormData.newEffectiveDate"
              type="date" 
              placeholder="年/月/日"
              style="width: 100%">
            </el-date-picker>
          </el-form-item>
        </el-form>
      </div>
      
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleSaveRenew">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import FileUpload from '@/components/FileUpload.vue';

export default {
  name: 'Zulinhetong',
  
  components: {
    FileUpload
  },
  
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
        districtUnit: "",
        managementDept: "",
        district: "",
        houseNumber: "",
        accessory: "",
        address: "",
        managementType: "",
        propertyType: "",
        doorNumber: "",
        nature: "",
        business: "",
        tenant: "",
        contractNumber: "",
        idNumber: "",
        securityDeposit: "",
        profitable: "",
        date: ""
      },
      total: 0,
      list: [
        {
          id: 1,
          contractNumber: "614684964",
          contractTextNumber: "614684964", 
          signContract: "是",
          terminateContract: "",
          startRent: "2025-05-06",
          stopRent: "2025-05-06",
          tenant: "李四"
        },
        {
          id: 2,
          contractNumber: "614684964",
          contractTextNumber: "614684964",
          signContract: "是",
          terminateContract: "",
          startRent: "2025-05-06",
          stopRent: "2025-05-06",
          tenant: "李四"
        }
      ],
      listLoading: false,
      dialogVisible: false,
      submitLoading: false,
      dialogTitle: "租赁合同录入",
      isReadonly: false,
      currentEditId: null,
      uploadDialogVisible: false,
      currentUploadContract: {},
      printDialogVisible: false,
      renewDialogVisible: false,
      currentPrintContract: {},
      currentRenewContract: {},
      renewFormData: {
        newEffectiveDate: ''
      },
      formData: {
        contractNumber: "",
        contractTextNumber: "",
        signDate: "",
        terminateDate: "",
        startRentDate: "",
        stopRentDate: "",
        tenant: "",
        idType: "",
        idNumber: "",
        phoneNumber: "",
        machineNumber: "",
        district: "",
        houseNumber: "",
        doorNumber: "",
        propertyType: "",
        roomNumber: "",
        address: "",
        propertyCategory: "",
        managementType: "",
        nature: "",
        isComplete: "",
        profitable: "",
        roomCount: "",
        exclusiveRooms: "",
        sharedRooms: "",
        exclusiveSharedRooms: "",
        sharedSharedRooms: "",
        reducedRooms: "",
        rentAmount: "",
        profitLoss: "",
        rentStatus: "",
        monthlyReceived: "",
        verifiedReduction: "",
        jointContractDeposit: "",
        machineContractParts: "",
        remarks: ""
      },
      formRules: {
        contractNumber: [
          { required: true, message: '请输入合同编号', trigger: 'blur' }
        ],
        contractTextNumber: [
          { required: true, message: '请输入合同文本序号', trigger: 'blur' }
        ],
        tenant: [
          { required: true, message: '请输入承租人', trigger: 'blur' }
        ]
      }
    };
  },

  mounted() {
    this.total = this.list.length;
    this.getList();
  },

  methods: {
    // 分页大小改变
    handleSizeChange(val) {
      this.listQuery.page = 1;
      this.listQuery.limit = val;
      this.getList();
    },
    // 当前页改变
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.getList();
    },
    // 获取列表数据
    getList() {
      this.listLoading = true;
      setTimeout(() => {
        this.listLoading = false;
      }, 500);
    },
    // 搜索
    handleSearch() {
      this.listQuery.page = 1;
      this.getList();
      this.$message.success('查询完成');
    },
    // 重置表单
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.getList();
    },
    // 合同录入
    handleAddContract() {
      this.dialogTitle = "租赁合同录入";
      this.isReadonly = false;
      this.currentEditId = null;
      this.dialogVisible = true;
      this.resetFormData();
    },
    // 扫描件上传
    handleUploadScan(row) {
      this.uploadDialogVisible = true;
    },
    // 打印
    handlePrint(row) {
      this.currentPrintContract = row;
      this.printDialogVisible = true;
    },
    // 联签
    handleJointSign(row) {
      this.currentRenewContract = row;
      this.renewFormData.newEffectiveDate = '';
      this.renewDialogVisible = true;
    },
    // 修改记录
    handleUpdate(row) {
      this.dialogTitle = "租赁合同修改";
      this.isReadonly = false;
      this.currentEditId = row.id;
      this.fillFormData(row);
      this.dialogVisible = true;
    },
    // 查看详情
    handleView(row) {
      this.dialogTitle = "租赁合同详情";
      this.isReadonly = true;
      this.currentEditId = row.id;
      this.fillFormData(row);
      this.dialogVisible = true;
    },
    // 删除记录
    handleDelete(id) {
      this.$confirm('此操作将删除该条内容，请确认是否继续操作？', '删除提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.list = this.list.filter(item => item.id !== id);
        this.total = this.list.length;
        this.$message.success('删除成功!');
      }).catch(() => {
        this.$message.info('已取消删除');
      });
    },
    // 弹窗关闭
    handleDialogClose() {
      this.resetFormData();
      if (this.$refs.contractForm) {
        this.$refs.contractForm.resetFields();
      }
    },
    // 重置表单数据
    resetFormData() {
      this.formData = {
        contractNumber: "",
        contractTextNumber: "",
        signDate: "",
        terminateDate: "",
        startRentDate: "",
        stopRentDate: "",
        tenant: "",
        idType: "",
        idNumber: "",
        phoneNumber: "",
        machineNumber: "",
        district: "",
        houseNumber: "",
        doorNumber: "",
        propertyType: "",
        roomNumber: "",
        address: "",
        propertyCategory: "",
        managementType: "",
        nature: "",
        isComplete: "",
        profitable: "",
        roomCount: "",
        exclusiveRooms: "",
        sharedRooms: "",
        exclusiveSharedRooms: "",
        sharedSharedRooms: "",
        reducedRooms: "",
        rentAmount: "",
        profitLoss: "",
        rentStatus: "",
        monthlyReceived: "",
        verifiedReduction: "",
        jointContractDeposit: "",
        machineContractParts: "",
        remarks: ""
      };
    },
    // 填充表单数据
    fillFormData(row) {
      this.formData = {
        contractNumber: row.contractNumber || "",
        contractTextNumber: row.contractTextNumber || "",
        signDate: row.signDate || "",
        terminateDate: row.terminateDate || "",
        startRentDate: row.startRent || "",
        stopRentDate: row.stopRent || "",
        tenant: row.tenant || "",
        idType: "id_card",
        idNumber: "614684964",
        phoneNumber: "13666666666",
        machineNumber: "M001",
        district: "王三",
        houseNumber: "1",
        doorNumber: "101",
        propertyType: "住宅",
        roomNumber: "1-1-1",
        address: "天津市和平区某某街道",
        propertyCategory: "public",
        managementType: "1",
        nature: "1",
        isComplete: "li_si",
        profitable: "no",
        roomCount: "2",
        exclusiveRooms: "1",
        sharedRooms: "1",
        exclusiveSharedRooms: "0",
        sharedSharedRooms: "0",
        reducedRooms: "0",
        rentAmount: "350",
        profitLoss: "1",
        rentStatus: "正常",
        monthlyReceived: "350",
        verifiedReduction: "low_income",
        jointContractDeposit: "500",
        machineContractParts: "无",
        remarks: "测试备注"
      };
    },
    // 表单提交
    handleSubmit() {
      if (this.isReadonly) {
        this.dialogVisible = false;
        return;
      }
      
      this.$refs.contractForm.validate((valid) => {
        if (valid) {
          this.submitLoading = true;
          setTimeout(() => {
            this.submitLoading = false;
            this.dialogVisible = false;
            this.$message.success(this.currentEditId ? '修改成功！' : '新建成功！');
            this.getList();
          }, 1000);
        } else {
          this.$message.error('请填写完整信息');
          return false;
        }
      });
    },
    // 上传确认
    handleUploadConfirm(fileList) {
      if (fileList.length === 0) {
        this.$message.warning('请先选择要上传的文件');
        return;
      }
      
      // 这里可以实现实际的文件上传逻辑
      this.$message.success(`成功上传 ${fileList.length} 个扫描件`);
      this.uploadDialogVisible = false;
    },
    // 文件预览
    handleFilePreview(file) {
      this.$message.info(`预览文件: ${file.name}`);
      // 这里可以实现文件预览逻辑
    },
    // 上传弹窗关闭
    handleUploadClose() {
      this.currentUploadContract = {};
    },
    // 执行打印
    handleDoPrint() {
      this.$message.success('打印任务已发送到打印机');
      this.printDialogVisible = false;
    },
    // 关闭打印弹窗
    handlePrintDialogClose() {
      this.currentPrintContract = {};
    },
    // 保存续签
    handleSaveRenew() {
      if (!this.renewFormData.newEffectiveDate) {
        this.$message.warning('请选择新的生效日期');
        return;
      }
      
      // 模拟保存续签操作
      this.$message.success('合同续签成功');
      this.renewDialogVisible = false;
      this.getList(); // 刷新列表
    },
    // 关闭续签弹窗
    handleRenewDialogClose() {
      this.currentRenewContract = {};
      this.renewFormData.newEffectiveDate = '';
    }
  }
};
</script>

<style scoped>
/* 页面样式继承公共样式类 publicpageview, publicformview, publitableview */

/* 合同录入弹窗样式 */
.contract-form {
  padding: 20px;
}

.section-title {
  margin: 20px 0 15px 0;
  font-size: 16px;
  font-weight: 500;
  color: #409eff;
  border-left: 4px solid #409eff;
  padding-left: 10px;
}

.section-title:first-child {
  margin-top: 0;
}

.contract-form .el-form-item {
  margin-bottom: 15px;
}

.contract-form .el-form-item__label {
  text-align: right;
  font-weight: 500;
  color: #606266;
}

.dialog-footer {
  text-align: center;
  padding-top: 20px;
}

/* 打印弹窗样式 */
.print-container {
  padding: 20px 0;
  text-align: center;
}

.print-preview {
  height: 300px;
  border: 1px solid #e4e7ed;
  border-radius: 4px;
  background-color: #fafafa;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

.print-style-text {
  font-size: 16px;
  color: #909399;
}

/* 续签弹窗样式 */
.renew-container {
  padding: 20px 0;
}
</style>